﻿<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html><head>
<meta charset="utf-8">
<title>核对订单信息_蜗牛图书商城</title>
<link rel="stylesheet" type="text/css" href="css/index.css">
<script type="text/javascript" src="js/jquery-3.4.1.js"></script>
<script type="text/javascript" src="js/private/global.js"></script>
<script>

</script>
</head>
<body class="second">
	<div class="brand_list container_2">
		<div class="header" id="header">
		<h1 class="logo">
			<a title="" style="background:url(images/logo.png);" href="index.jsp">电子商务平台</a>
		</h1>
		<!-- <ul class="shortcut">
			<li class="first"><a href="personal.html">个人中心</a></li>
			<li><a href="myOrders.html">我的订单</a></li>
		</ul>
		<p class="loginfo">

				laotan！您好，欢迎您来到购物！[<a
					href="user?opr=logout" class="reg">安全退出</a>]


		</p> -->
			<div id="login"></div>
			<script>
				let user =  window.sessionStorage.getItem("user");
				if(user!=undefined){
					var $ul="<ul class=\"shortcut\">\n" +
							"        <li class=\"first\"><a href=\"personal.html\">个人中心</a></li>\n" +
							"        <li><a href=\"myOrders.html\">我的订单</a></li>\n" +
							"        <p class=\"loginfo\">你好!"+""+"[<a href=\"javaScript:logout()\">安全退出</a>]</p>\n" +
							"    </ul>";

					$("#login").html($ul);


				}else{
					var $p="<p class=\"loginfo\">\n" +
							"        [<a href=\"login.html\">登录</a> <a class=\"reg\" href=\"adduser.html\">免费注册</a>]\n" +
							"    </p>";
					$("#login").html($p);
				}
			</script>
			<!--				<ul class="shortcut">-->
			<!--					<li class="first">-->
			<!--						<a href="personal.html">个人中心</a>-->
			<!--					</li>-->
			<!--					<li>-->
			<!--						<a href="myOrders.html">我的订单</a>-->
			<!--					</li>-->
			<!--				</ul>-->
			<!--				<p class="loginfo">你好!17760990684[-->
			<!--					<a href="javaScript:logout()">安全退出</a>]</p>-->
		</div>
		<div class="wrapper clearfix">
			<div class="position mt_10">
				<span>您当前的位置：</span> <a href="index.jsp"> 首页</a> » 填写核对订单信息
			</div>
			<div class="myshopping m_10">
				<ul class="order_step">
					<li class="current_prev"><span class="first"><a href="javascript:history.go(-1);">1、查看购物车</a></span></li>
					<li class="current"><span>2、填写核对订单信息</span></li>
					<li class="last"><span>3、成功提交订单</span></li>
				</ul>
			</div>

		<!-- 	<form action='order' method='post' name='order_form'> -->
				<input type="hidden" name="opr" value="add">
				<div class="cart_box m_10">
					<div class="title">填写核对订单信息</div>
					<div class="cont">

						<!--地址管理 开始-->
						<div class="wrap_box">
							<h3>
								<span class="orange">收货人信息</span>
							</h3>
							<!--收货表单信息 开始-->
							<div class="prompt_4 m_10" id="address_often">
								<strong>常用收货地址</strong>
								<ul class="addr_list" id="address"><li><label><input class="radio" checked="checked" name="addresses" type="radio" value="1"><span>许敏</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>17768689999</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>四川省</span><span>成都市</span><span>高新区</span><span>软件孵化园</span></label></li><li><label><input class="radio" name="addresses" type="radio" value="2"><span>admin</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>17788886666</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>四川省</span><span>成都市</span><span>锦江区</span><span>桂花街303号</span></label></li></ul>
							</div>
						</div>
						<!--地址管理 结束-->
						<!--支付方式 开始-->
						<div class="wrap_box" id="paymentBox">
							<h3>
								<span class="orange">支付方式</span>
							</h3>

							<table width="100%" class="border_table" id="payment_form">
								<colgroup><col width="200px">
								<col>
								</colgroup><tbody><tr>
									<th><label><input class="radio" name="paytype" alt="0" title="支付宝" type="radio" value="1" checked="checked">支付宝</label></th>
									<td>支付手续费：￥0</td>
								</tr>
								<!-- <tr>
									<th><label><input class="radio" name="paytype"
											alt="0" title="货到付款" type="radio" value="2" />货到付款</label></th>
									<td>支付手续费：￥0</td>
								</tr> -->
							</tbody></table>
						</div>
						<!--支付方式 结束-->
						<!--购买清单 开始-->
						<div class="wrap_box">
							<h3>
								<span class="orange">购买的商品</span>
							</h3>

							<table width="100%" class="cart_table t_c">
								<colgroup><col width="115px">
								<col>
								<col width="80px">
								<col width="80px">
								<col width="80px">

								</colgroup><thead>
									<tr>
										<th>图片</th>
										<th>商品名称</th>
										<th>单价</th>
										<th>数量</th>
										<th class="last">小计</th>
									</tr>
								</thead>

								<tbody id="myCart-list">

								</tbody>

							</table>
						</div>
						<!--购买清单 结束-->
					</div>
				</div>

				<!--金额结算-->
				<div class="cart_box" id="amountBox">
					<div class="cont_2">
						<strong>结算信息</strong>
						<div class="pink_box">
							<p class="f14 t_l">
								商品总金额：<b class="totalPrice">226</b> + 运费总计：<b id="delivery_fee_show">0.00</b>
							</p>
						</div>
						<hr class="dashed">
						<div class="pink_box gray m_10">
							<table width="100%" class="form_table t_l">
								<colgroup><col width="220px">
								<col>
								<col width="250px">
								</colgroup><tbody><tr>
									<td class="t_r"><b class="price f14">应付总额：<span class="red2">￥<b id="final_sum" class="totalPrice">226</b></span>元
									</b></td>
								</tr>
							</tbody></table>
						</div>
						<p class="m_10 t_r">
							<input type="button" class="submit_order" id="createOrder-btn">
						</p>
					</div>
				</div>

			<!-- </form> -->

		</div>
		<div class="footer">
		<p class="links">
			<a href="">关于我们</a>|<a href="">常见问题</a>|<a href="">安全交易</a>|<a href="">购买流程</a>|<a href="">如何付款</a>|<a href="">联系我们</a>|<a href="">合作提案</a>
		</p>
		Copyright © 2015-2021 <a class="copyys" target="_blank" href="">蜀ICP备01000010号</a>
	</div>
	</div>
	<script src="js/jquery-3.6.0.js"></script>
	<script>
		$(function (){
			let userString = window.sessionStorage.getItem("user");
			if(userString==null ||userString ==undefined){
				window.location.href = "login.html";
				return;
			}
			//获取用户id
			let userid = JSON.parse(userString).id;
			// "order_check.html?ids="+ids
			let url  = location.href;
			let ids = url.substring(url.indexOf("ids=")+4);
			$.ajax({
				type:"post",
				url:"cart.do",
				dataType:"json",
				data:{
					method:"orderCheck",
					ids:ids,
					userid:userid
				},
				success:function (result){
					if(result.code == 200){
						//显示收货地址
						let address = result.data.address;
						$.each(address,function (index,item){
							let addr = `<li><label><input class="radio" ${item.type == 'y'?checked="checked":""} name="addresses" type="radio"
								 value="${item.id}"><span>${item.accept}</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>${item.telphone}</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>${item.province}</span><span>${item.city}</span><span>${item.area}</span><span>${item.address}</span></label>
						   </li>`;
							$("#address").append(addr);
						});
						//显示商品列表
						let carts = result.data.cartsByIds;
						let allmoney = 0;
						$.each(carts,function (index,item){
							let booktr = ` <tr>
						  <td><img src="${item.goods.image}" width="66px"
							 height="66px"
							 alt="${item.goods.name}"
							 title="${item.goods.name}">
						  </td>
						  <td class="t_l"><a href="goods?opr=view&amp;id=518" class="blue" target="_blank">${item.goods.name}</a>
						  </td>
						  <td>￥<b>${item.goods.salesprice}</b></td>
						  <td>${item.nums}</td>
						  <td>￥<b class="red2">${item.goods.salesprice*item.nums}</b></td>
						 </tr>`;
							allmoney+=item.goods.salesprice*item.nums;
							$("#myCart-list").append(booktr);
						});
						$("#totalPrice").html(allmoney.toFixed(2));
						$("#final_sum").html(allmoney.toFixed(2));
					}
				}
			});
			$("#createOrder-btn").click(function (){
				//获取收货地址id
				let addressid = $(":checked[name=addresses]").val();
				//获取ids
				let url  = location.href;
				let ids = url.substring(url.indexOf("ids=")+4);
				//获取支付方式
				let paymethod = $(":checked[name=paytype]").val();
				$.ajax({
					type: "post",
					url:"order.do",
					resultType:"json",
					data: {
						method: "addOrder",
						addressid:addressid,
						ids:ids,
						paymethod:paymethod
					},
					success:function (result){
						if(result.code == 200){
							window.sessionStorage.setItem("order",JSON.stringify(result.data));
							location.href="order_success.html";
						}
					}
				});
			});
		});
	</script>
</body></html>
